package com.wangnan.currentactivity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wangnan.currentactivity.Dao.BillList;
import com.wangnan.currentactivity.R;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/*
 * Package    :com.wangnan.currentactivity.adapter
 * ClassName  :MyAdapter
 * Description:
 * Data       :2021/1/27/027 9:55
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {

	Context        context;
	List<BillList> datas;


	public MyAdapter(Context context) {
		this.context = context;
	}

	public void setAlldatas(List<BillList> datas) {
		this.datas = datas;
	}

	@NonNull
	@Override
	public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
		return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_me_bill, viewGroup, false));
	}

	@Override
	public void onBindViewHolder(@NonNull final MyHolder myHolder, final int i) {
		String textshow = "交易时间 = " + datas.get(i).getBilltime() + "\n" +
				"金额 = " + datas.get(i).getBillAmount() + "\n" +
				"备注 = " + datas.get(i).getBillRmarkse() + "\n" +
				"状态 = " + datas.get(i).getBillStatus() + "\n" +
				"消费名称 = " + datas.get(i).getBillName() + "\n"+
				"平台名称 = " + datas.get(i).getIsBillType() + "\n";
		myHolder.Tvbillcontext.setText(textshow);
		myHolder.Tvbillname.setText("时间戳="+datas.get(i).getId());


	}

	@Override
	public int getItemCount() {
		//如果有这条语句是不会报错的，但是RecyclerView获取不到数据
		if (null == datas) {
			return 0;
		} else {
			return datas.size();
		}

	}

	public class MyHolder extends RecyclerView.ViewHolder {

		private TextView Tvbillname;
		private TextView Tvbillcontext;

		public MyHolder(@NonNull View itemView) {
			super(itemView);
			Tvbillname = itemView.findViewById(R.id.tv_bill_name);
			Tvbillcontext = itemView.findViewById(R.id.tv_bill_context);
		}
	}
}